package org.zffc.common.util.helper;

import lombok.Data;

import java.util.List;

/**
 * 分页结果封装类
 * @param <T> 数据类型
 */
@Data
public class PageResult<T> {
    /**
     * 分页数据
     */
    private List<T> records;

    /**
     * 分页大小
     */
    private Integer size;
    /**
     * 当期页码 从1开始
     */
    private Integer current;
    /**
     * 数据总数
     */
    private Long total;

    public PageResult() {}

    public PageResult(int currentPage, int size) {
        this.current = currentPage;
        this.size = size;
    }

    public PageResult(Long total) {
        this.total = total;
    }

    public PageResult(List<T> data, int currentPage, int pageSize, long total) {
        this.records = data;
        this.current = currentPage;
        this.size = pageSize;
        this.total = total;
    }


    public void from(PageResult<T> pageResult) {
        setSize(pageResult.size);
        setCurrent(pageResult.current);
        setTotal(pageResult.total);
        setRecords(pageResult.records);
    }

    public PageResult<T> into(PageResult<T> into) {
        into.from(this);
        return into;
    }
}
